package com.dlc.shop.systemtest.data.maketing;

import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.dlc.shop.seckill.common.model.SeckillSku;
import com.dlc.shop.seckill.multishop.param.SeckillParam;
import com.dlc.shop.systemtest.api.amount.SkuApi;

import java.util.List;

/**
 * @author lanhai
 * 秒杀测试数据
 */
public class SeckillData {
    public static SeckillParam getSeckillParam(Long prodId){
        SeckillParam seckill = new SeckillParam();
        seckill.setSeckillName("测试秒杀接口");
        System.out.println(DateUtil.parse("2021-1-1 00:00:00","yyyy-MM-dd HH:mm:ss"));
        seckill.setStartTime(DateUtil.parse("2021-1-1 00:00:00","yyyy-MM-dd HH:mm:ss"));
        seckill.setEndTime(DateUtil.parse("2024-1-1 00:00:00","yyyy-MM-dd HH:mm:ss"));
        seckill.setMaxCancelTime(2);
        seckill.setProdId(prodId);
        seckill.setMaxNum(-1);
        List skuList = SkuApi.getAllSkuList(prodId);
        List<SeckillSku> seckillSkuList = JSON.parseArray(JSONObject.toJSONString(skuList), SeckillSku.class);
        seckillSkuList.forEach(i->{
            i.setSeckillPrice(1.00);
            i.setSeckillStocks(10);
        });
        seckill.setSeckillSkus(seckillSkuList);
        return seckill;
    }

    public static SeckillParam getSeckillParam(Long prodId, Double price, Integer stocks){
        SeckillParam seckill = new SeckillParam();
        seckill.setSeckillName("测试秒杀接口");
        seckill.setStartTime(DateUtil.parse("2021-1-1 00:00:00","yyyy-MM-dd HH:mm:ss"));
        seckill.setEndTime(DateUtil.parse("2025-1-1 00:00:00","yyyy-MM-dd HH:mm:ss"));
        seckill.setMaxCancelTime(2);
        seckill.setProdId(prodId);
        seckill.setMaxNum(-1);
        List skuList = SkuApi.getAllSkuList(prodId);
        List<SeckillSku> seckillSkuList = JSON.parseArray(JSONObject.toJSONString(skuList), SeckillSku.class);
        seckillSkuList.forEach(i->{
            i.setSeckillPrice(price);
            i.setSeckillStocks(stocks);
        });
        seckill.setSeckillSkus(seckillSkuList);
        return seckill;
    }

}
